package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.WeekResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.RechargeOrder;
import com.ruoyi.system.service.IRechargeOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 充值订单Controller
 * 
 * @author ruoyi
 * @date 2025-06-28
 */
@RestController
@RequestMapping("/system/rorder")
public class RechargeOrderController extends BaseController
{
    @Autowired
    private IRechargeOrderService rechargeOrderService;

    /**
     * 查询充值订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:rorder:list')")
    @GetMapping("/list")
    public TableDataInfo list(RechargeOrder rechargeOrder)
    {
        startPage();
        List<RechargeOrder> list = rechargeOrderService.selectRechargeOrderList(rechargeOrder);
        return getDataTable(list);
    }

    /**
     * 导出充值订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:rorder:export')")
    @Log(title = "充值订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RechargeOrder rechargeOrder)
    {
        List<RechargeOrder> list = rechargeOrderService.selectRechargeOrderList(rechargeOrder);
        ExcelUtil<RechargeOrder> util = new ExcelUtil<RechargeOrder>(RechargeOrder.class);
        util.exportExcel(response, list, "充值订单数据");
    }

    /**
     * 获取充值订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rorder:query')")
    @GetMapping(value = "/{roId}")
    public AjaxResult getInfo(@PathVariable("roId") Integer roId)
    {
        return success(rechargeOrderService.selectRechargeOrderByRoId(roId));
    }

    /**
     * 新增充值订单
     */
    @PreAuthorize("@ss.hasPermi('system:rorder:add')")
    @Log(title = "充值订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RechargeOrder rechargeOrder)
    {
        return toAjax(rechargeOrderService.insertRechargeOrder(rechargeOrder));
    }

    /**
     * 修改充值订单
     */
    @PreAuthorize("@ss.hasPermi('system:rorder:edit')")
    @Log(title = "充值订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RechargeOrder rechargeOrder)
    {
        return toAjax(rechargeOrderService.updateRechargeOrder(rechargeOrder));
    }

    /**
     * 删除充值订单
     */
    @PreAuthorize("@ss.hasPermi('system:rorder:remove')")
    @Log(title = "充值订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{roIds}")
    public AjaxResult remove(@PathVariable Integer[] roIds)
    {
        return toAjax(rechargeOrderService.deleteRechargeOrderByRoIds(roIds));
    }

    /**
     * 获取本周每日充值金额
     */
    @GetMapping("/selectWeekRechargeAmount")
    public List<WeekResult> selectWeekRechargeAmount(){
        return rechargeOrderService.selectWeekRechargeAmount();
    };

    /**
     * 获取上周每日充值金额
     */
    @GetMapping("/selectLastWeekRechargeAmount")
    public List<WeekResult> selectLastWeekRechargeAmount(){
        return rechargeOrderService.selectLastWeekRechargeAmount();
    };

    /**
     * 获取今日充值金额
     */
    @GetMapping("/selectTodayRechargeAmount")
    public Double selectTodayRechargeAmount(){
        return rechargeOrderService.selectTodayRechargeAmount();
    };

    /**
     * 获取昨天充值金额
     */
    @GetMapping("/selectYesterdayRechargeAmount")
    public Double selectYesterdayRechargeAmount(){
        return rechargeOrderService.selectYesterdayRechargeAmount();
    };
}
